#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
	double n;
	cin >> n;
	string s;
	cin >> s;
	int cnt0 = 0;
	int cnt1 = 0;
	//左边至少一半是0，右边至少一半是1
	for(int i = 0;i < s.size();i++){
		if(s[i] == '0'){
			cnt0++;
		}else{
			cnt1++;
		}
	}
	int cntt0 = 0;
	int cntt1 = 0;
	vector<int> v;
	int cnt = 0;
	if((cnt0-cntt0) <= (cnt1-cntt1)){
		v.push_back(0);
	}
	for(int i = 0;i < s.size();i++){
		if(s[i] == '0'){
			cntt0++;
		}else{
			cntt1++;
		}
		if(cntt0 >= cntt1 && (cnt0-cntt0) <= (cnt1-cntt1)){
			v.push_back(i + 1);
			cnt++;
		}
	}
	if(v.empty()){
		cout << 0 << "\n";
		return ;
	}
	double temp = 100000000;
	int index = 0;
	for(auto i = v.begin();i < v.end();i++){
		if(abs(n/2 - *i) < temp){
			temp = abs(n/2 - *i);
			index = *i;
		}
	}
	cout << index << "\n";
}
int main(){
	ios::sync_with_stdio(false),cin.tie(0);
	int t = 1;
	cin >> t;
	while(t--) solve();
}